﻿using UnityEngine;
using System.Data;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using UnityEngine.UI;

public class PaiHangBang : MonoBehaviour
{
    static object name;
    static object age;

    static Text idOne;
    static Text scoreOne;
    static Text idTwo;
    static Text scoreTwo;
    static Text idThree;
    static Text scoreThree;

    //字典
    static Dictionary<object, object> dic = new Dictionary<object, object>();
    //static int[] arr = new int[10];


    private void Start()
    {
        MySqlAccess.OpenSql();
        idOne = GameObject.Find("Canvas").transform.Find("排行榜面板/ID1").gameObject.GetComponent<Text>();
        scoreOne = GameObject.Find("Canvas").transform.Find("排行榜面板/分数1").gameObject.GetComponent<Text>();
        idTwo = GameObject.Find("Canvas").transform.Find("排行榜面板/ID2").gameObject.GetComponent<Text>();
        scoreTwo = GameObject.Find("Canvas").transform.Find("排行榜面板/分数2").gameObject.GetComponent<Text>();
        idThree = GameObject.Find("Canvas").transform.Find("排行榜面板/ID3").gameObject.GetComponent<Text>();
        scoreThree = GameObject.Find("Canvas").transform.Find("排行榜面板/分数3").gameObject.GetComponent<Text>();
    }

    //查询数据库表
    public static void Query()
    {
        DataSet s = MySqlAccess.SelectAllGold();
        DataTable ta = s.Tables[0];
        int[] arr = new int[ta.Rows.Count];
        List<int> arrs = new List<int>();
        foreach (DataRow row in ta.Rows)//行
        {
            foreach (DataColumn column in ta.Columns)//列
            {
                arrs.Add(int.Parse(row[column].ToString()));
            }
        }
        for (int i = 0; i < arr.Length; i++)
        {
            arr[i] = arrs[i];
        }
        Array.Sort(arr);
        //榜一
        idOne.text = MySqlAccess.QueryIDS(arr[arr.Length - 1].ToString());
        scoreOne.text = arr[arr.Length - 1].ToString();
        //榜二
        idTwo.text = MySqlAccess.QueryIDS(arr[arr.Length - 2].ToString());
        scoreTwo.text = arr[arr.Length - 2].ToString();
        //榜三
        idThree.text = MySqlAccess.QueryIDS(arr[arr.Length - 3].ToString());
        scoreThree.text = arr[arr.Length - 3].ToString();
    }
}
